<?php

namespace Gds\VenteBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Doctrine\ORM\EntityRepository;

class SessionCaisseType extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
                ->add('date', 'date', array('widget' => 'single_text', 'format' => 'dd/MM/yyyy H:s'))
                ->add('solde_initial')
                ->add('caisse', 'entity', array(
                    'class' => 'GdsVenteBundle:Caisse',
                    'query_builder' => function(EntityRepository $er) {
                        return $er->createQueryBuilder('c')
                                ->where('c.is_active =:is_active')
                                ->orderBy('c.code', 'ASC')
                                ->setParameter('is_active', false);
                    },
                ))
                ->add('user', 'entity', array(
                    'class' => 'GdsUserBundle:User',
                    'query_builder' => function(EntityRepository $er) {
                                
                        return $er->createQueryBuilder('u')
                                ->where('u.is_caissier =:is_caissier')
                                ->orderBy('u.nom', 'ASC')
                                ->setParameter('is_caissier', false);
                    },
                ))
        ;
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver) {
        $resolver->setDefaults(array(
            'data_class' => 'Gds\VenteBundle\Entity\SessionCaisse'
        ));
    }

    public function getName() {
        return 'gds_ventebundle_sessioncaissetype';
    }

}
